package com.steven.im.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

/**
 * Created by Steven on 2019/2/12.
 * 格式化数据
 */
public class FormattedDataUtils {
    //时间转换  返回格式：00:00:00
    public static String getLastTime(long time) {
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//这里想要只保留分秒可以写成"mm:ss"
            formatter.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
            return formatter.format(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "0";
    }

    //格式化double数据
    public static String getFormatDouble(String db) {
        try {
            double v = Double.parseDouble(db);
            DecimalFormat df_0 = new DecimalFormat("0.00");
            return df_0.format(v);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return db;
    }

    //把小数转换成百分数
    public static String decimalToPercentage(String db) {
        try {
            double result1 = Double.parseDouble(db);
            DecimalFormat df_1 = new DecimalFormat("0.00%");
            return df_1.format(result1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return db;
    }
}
